﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.SiteDefaultBotEngines.Service
{
    public class SiteDefaultBotEngineAppService : BaseAppService, ISiteDefaultBotEngineAppService
    {
        private ISiteDefaultBotEngineDomainService _domainService;

        public SiteDefaultBotEngineAppService(ISiteDefaultBotEngineDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SITEDEFAULTBOTENGINE, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SITEDEFAULTBOTENGINE, AuditAction.CREATE)]
        public SiteDefaultBotEngineDto Add(SiteDefaultBotEngineCreateDto dto)
        {
            SiteDefaultBotEngine siteDefaultBotEngine = _domainService.Create(Mapper.Map<SiteDefaultBotEngine>(dto));
            return Mapper.Map<SiteDefaultBotEngineDto>(siteDefaultBotEngine);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SITEDEFAULTBOTENGINE, AuditAction.UPDATE)]
        public SiteDefaultBotEngineDto Update(SiteDefaultBotEngineUpdateDto dto)
        {
            SiteDefaultBotEngine siteDefaultBotEngine = _domainService.Update(Mapper.Map<SiteDefaultBotEngineUpdateBo>(dto));
            return Mapper.Map<SiteDefaultBotEngineDto>(siteDefaultBotEngine);
        }

        public SiteDefaultBotEngineDto Get(Guid id)
        {
            SiteDefaultBotEngine siteDefaultBotEngine = _domainService.Get(id);
            return Mapper.Map<SiteDefaultBotEngineDto>(siteDefaultBotEngine);
        }

        public IEnumerable<SiteDefaultBotEngineDto> GetList()
        {
            IEnumerable<SiteDefaultBotEngine> list = _domainService.List();
            return Mapper.Map<IEnumerable<SiteDefaultBotEngineDto>>(list);
        }
    }
}
